package com.txf.simple.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aspsine.swipetoloadlayout.SwipeRefreshTrigger;
import com.aspsine.swipetoloadlayout.SwipeTrigger;
import com.txf.simple.R;
import com.txf.simple.tools.Logger;

/**
 * @author txf
 * @Title 自定义刷新头部View
 * @package com.txf.simple.ui.view
 * @date 2016/11/22 0022
 */

public class SwipeRefreshView extends RelativeLayout implements SwipeTrigger, SwipeRefreshTrigger {
    private TextView headerviewTv;
    private ProgressBar headerProgressBar;

    public SwipeRefreshView(Context context) {
        super(context);
        init();
    }

    public SwipeRefreshView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public SwipeRefreshView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }
    private void init() {

    }
    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        LayoutInflater.from(getContext()).inflate(R.layout.view_swipe_refresh_layout, this);
        headerviewTv = (TextView) findViewById(R.id.headerviewTv);
        headerProgressBar = (ProgressBar) findViewById(R.id.headerProgressBar);
    }
    @Override
    public void onRefresh() {
        headerviewTv.setText("刷新中...");
    }
    @Override
    public void onPrepare() {
    }
    @Override
    public void onMove(int i, boolean b, boolean b1) {
        Logger.i("onMove" +
                "i : " + i +
                " , b :" + b +
                " , b1 : " + b1
        );
        if (i > 150)
            headerviewTv.setText("释放刷新");
        else if(b && b1)
            headerviewTv.setText("        ");
        else
            headerviewTv.setText("下拉刷新");
    }
    @Override
    public void onRelease() {
    }
    @Override
    public void onComplete() {
        headerviewTv.setText("刷新成功");
    }
    @Override
    public void onReset() {
    }
}
